from SketchAPI import *

from salome.shaper import model

model.begin()
partSet = model.moduleDocument()
Part_1 = model.addPart(partSet)
Part_1_doc = Part_1.document()
anAngle = model.addParameter(Part_1_doc, "angle", "45")
model.addParameter(Part_1_doc, "r1", "0.6671")
model.addParameter(Part_1_doc, "ep", "0.02")
Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("YOZ"))
SketchLine_1 = Sketch_1.addLine(1.25, 4.0171, 1.25, 2.5971)
SketchLine_2 = Sketch_1.addLine(1.25, 2.5971, 1.4, 2.5971)
SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
SketchLine_3 = Sketch_1.addLine(1.4, 2.5971, 1.4, 2.0871)
SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
SketchLine_4 = Sketch_1.addLine(1.4, 2.0871, 1.25, 2.0871)
SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_1.result())
SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_3.result())
SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_4.result())
SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_2.result())
SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False)
SketchLine_5 = SketchProjection_1.createdFeature()
SketchLine_5.setName("SketchLine_6")
SketchLine_5.result().setName("SketchLine_6")
SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OZ"), False)
SketchLine_6 = SketchProjection_2.createdFeature()
SketchLine_6.setName("SketchLine_7")
SketchLine_6.result().setName("SketchLine_7")
SketchLine_7 = Sketch_1.addLine(1.25, 2.0871, 1.25, 0.6671)
SketchLine_7.setName("SketchLine_12")
SketchLine_7.result().setName("SketchLine_12")
SketchEllipticArc_1 = Sketch_1.addEllipticArc(0, 0.6671, 1.057108125973878, 0.6671, 0, 2.733995794193338e-31, 1.25, 0.6671000000000001, False)
[SketchPoint_1, SketchPoint_2, SketchPoint_3, SketchPoint_4, SketchPoint_5, SketchPoint_6, SketchPoint_7, SketchLine_8, SketchLine_9] = SketchEllipticArc_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux")
SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_9.result())
SketchConstraintVertical_3.setName("SketchConstraintVertical_4")
SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_9).startPoint(), SketchEllipticArc_1.startPoint())
SketchConstraintCoincidence_4.setName("SketchConstraintCoincidence_22")
SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchEllipticArc_1.endPoint(), SketchAPI_Point(SketchPoint_5).coordinates())
SketchConstraintCoincidence_5.setName("SketchConstraintCoincidence_23")
SketchConstraintDistance_1 = Sketch_1.setDistance(SketchEllipticArc_1.minorAxisNegative(), SketchLine_8.result(), "r1", True)
SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchEllipticArc_1.majorAxisPositive())
SketchConstraintCoincidence_6.setName("SketchConstraintCoincidence_27")
SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_7.result())
SketchConstraintVertical_4.setName("SketchConstraintVertical_5")
SketchConstraintDistance_2 = Sketch_1.setDistance(SketchEllipticArc_1.majorAxisPositive(), SketchLine_6.result(), 1.25, True)
SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_7.result(), 1.42)
SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_7.startPoint())
SketchConstraintCoincidence_7.setName("SketchConstraintCoincidence_13")
SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_7.result())
SketchConstraintCoincidence_8.setName("SketchConstraintCoincidence_14")
SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_3.result(), 0.51)
SketchConstraintLength_3 = Sketch_1.setLength(SketchLine_2.result(), 0.15)
SketchConstraintLength_4 = Sketch_1.setLength(SketchLine_1.result(), 1.42)
SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchEllipticArc_1.minorAxisNegative(), SketchLine_5.result())
SketchConstraintCoincidence_9.setName("SketchConstraintCoincidence_9")
SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_6).coordinates(), SketchLine_6.result())
SketchConstraintCoincidence_10.setName("SketchConstraintCoincidence_10")
SketchEllipticArc_2 = Sketch_1.addEllipticArc(0, 4.0171, 1.057108125973878, 4.0171, 1.25, 4.0171, -1.323488743421758e-23, 4.6842, False)
[SketchPoint_8, SketchPoint_9, SketchPoint_10, SketchPoint_11, SketchPoint_12, SketchPoint_13, SketchPoint_14, SketchLine_10, SketchLine_11] = SketchEllipticArc_2.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux")
SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_6.result(), SketchEllipticArc_2.center())
SketchConstraintCoincidence_11.setName("SketchConstraintCoincidence_11")
SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchEllipticArc_2.startPoint(), SketchAPI_Line(SketchLine_10).endPoint())
SketchConstraintCoincidence_12.setName("SketchConstraintCoincidence_12")
SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchEllipticArc_2.endPoint(), SketchAPI_Line(SketchLine_11).endPoint())
SketchConstraintCoincidence_13.setName("SketchConstraintCoincidence_15")
SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_10.result())
SketchConstraintCoincidence_14 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_12).coordinates(), SketchLine_1.startPoint())
SketchConstraintCoincidence_14.setName("SketchConstraintCoincidence_16")
SketchConstraintDistance_3 = Sketch_1.setDistance(SketchEllipticArc_2.minorAxisPositive(), SketchLine_10.result(), "r1", True)
SketchLine_12 = Sketch_1.addLine(1.229999999999999, 4.0171, 1.229999999999999, 0.6671)
SketchLine_12.setName("SketchLine_13")
SketchLine_12.result().setName("SketchLine_13")
SketchConstraintCoincidence_15 = Sketch_1.setCoincident(SketchLine_12.startPoint(), SketchLine_10.result())
SketchConstraintCoincidence_15.setName("SketchConstraintCoincidence_17")
SketchConstraintCoincidence_16 = Sketch_1.setCoincident(SketchLine_12.endPoint(), SketchLine_8.result())
SketchConstraintCoincidence_16.setName("SketchConstraintCoincidence_18")
SketchConstraintVertical_5 = Sketch_1.setVertical(SketchLine_12.result())
SketchConstraintVertical_5.setName("SketchConstraintVertical_6")
SketchConstraintDistance_4 = Sketch_1.setDistance(SketchLine_12.startPoint(), SketchLine_1.result(), "ep", True)
SketchEllipticArc_3 = Sketch_1.addEllipticArc(0, 4.0171, 1.046021792316405, 4.0171, 0, 4.664199999999999, 1.23, 4.0171, True)
[SketchPoint_15, SketchPoint_16, SketchPoint_17, SketchPoint_18, SketchPoint_19, SketchPoint_20, SketchPoint_21, SketchLine_13, SketchLine_14] = SketchEllipticArc_3.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux")
SketchConstraintCoincidence_17 = Sketch_1.setCoincident(SketchEllipticArc_2.center(), SketchEllipticArc_3.center())
SketchConstraintCoincidence_17.setName("SketchConstraintCoincidence_19")
SketchConstraintCoincidence_18 = Sketch_1.setCoincident(SketchLine_6.result(), SketchEllipticArc_3.startPoint())
SketchConstraintCoincidence_18.setName("SketchConstraintCoincidence_20")
SketchConstraintCoincidence_19 = Sketch_1.setCoincident(SketchLine_10.result(), SketchEllipticArc_3.endPoint())
SketchConstraintCoincidence_19.setName("SketchConstraintCoincidence_21")
SketchConstraintCoincidence_20 = Sketch_1.setCoincident(SketchEllipticArc_3.endPoint(), SketchLine_12.startPoint())
SketchConstraintCoincidence_20.setName("SketchConstraintCoincidence_24")
SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchEllipticArc_2.minorAxisPositive(), SketchEllipticArc_3.startPoint(), "ep")
SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_13.result())
SketchEllipticArc_4 = Sketch_1.addEllipticArc(0, 0.6671, 1.046021792316011, 0.6671, 0, 0.02, 1.229999999999999, 0.6670999999999999, False)
[SketchPoint_22, SketchPoint_23, SketchPoint_24, SketchPoint_25, SketchPoint_26, SketchPoint_27, SketchPoint_28, SketchLine_15, SketchLine_16] = SketchEllipticArc_4.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux")
SketchConstraintCoincidence_21 = Sketch_1.setCoincident(SketchEllipticArc_1.center(), SketchEllipticArc_4.center())
SketchConstraintCoincidence_21.setName("SketchConstraintCoincidence_25")
SketchConstraintCoincidence_22 = Sketch_1.setCoincident(SketchLine_12.endPoint(), SketchEllipticArc_4.result())
SketchConstraintCoincidence_22.setName("SketchConstraintCoincidence_26")
SketchConstraintCoincidence_23 = Sketch_1.setCoincident(SketchLine_6.result(), SketchEllipticArc_4.startPoint())
SketchConstraintCoincidence_23.setName("SketchConstraintCoincidence_28")
SketchConstraintCoincidence_24 = Sketch_1.setCoincident(SketchLine_12.endPoint(), SketchEllipticArc_4.endPoint())
SketchConstraintCoincidence_24.setName("SketchConstraintCoincidence_29")
SketchConstraintDistanceVertical_2 = Sketch_1.setVerticalDistance(SketchEllipticArc_4.minorAxisNegative(), SketchEllipticArc_1.minorAxisNegative(), "ep")
SketchConstraintHorizontal_5 = Sketch_1.setHorizontal(SketchLine_15.result())
SketchLine_17 = Sketch_1.addLine(9.702173021404511e-32, 0.02, -2.296340201324298e-16, -1.110223024625157e-16)
SketchConstraintCoincidence_25 = Sketch_1.setCoincident(SketchEllipticArc_4.minorAxisNegative(), SketchLine_17.startPoint())
SketchConstraintCoincidence_25.setName("SketchConstraintCoincidence_30")
SketchConstraintCoincidence_26 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_5).startPoint(), SketchLine_17.endPoint())
SketchConstraintCoincidence_26.setName("SketchConstraintCoincidence_31")
SketchLine_18 = Sketch_1.addLine(7.654042494670958e-17, 4.684199999999996, 7.524363077049401e-17, 4.664199999999999)
SketchConstraintCoincidence_27 = Sketch_1.setCoincident(SketchEllipticArc_2.minorAxisPositive(), SketchLine_18.startPoint())
SketchConstraintCoincidence_27.setName("SketchConstraintCoincidence_32")
SketchConstraintCoincidence_28 = Sketch_1.setCoincident(SketchEllipticArc_3.minorAxisPositive(), SketchLine_18.endPoint())
SketchConstraintCoincidence_28.setName("SketchConstraintCoincidence_33")
model.do()
Revolution_1 = model.addRevolution(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchEllipticArc_2f-SketchLine_18f-SketchEllipticArc_3r-SketchLine_13f-SketchEllipticArc_4r-SketchLine_17f-SketchEllipticArc_1f-SketchLine_12r-SketchLine_4r-SketchLine_3r-SketchLine_2r-SketchLine_1r")], model.selection("EDGE", "PartSet/OZ"), "angle", 0)
Group_1_objects = [model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchEllipticArc_4"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchLine_13"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchEllipticArc_3")]
Group_1 = model.addGroup(Part_1_doc, "Faces", Group_1_objects)
Group_1.setName("Group_int")
Group_1.result().setName("Group_int")
Group_1.result().setColor(170, 0, 0)
Group_2_objects = [model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchEllipticArc_2"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchLine_1"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchLine_2"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchLine_3"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchLine_4"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchLine_12"), model.selection("FACE", "Revolution_1_1/Generated_Face&Sketch_1/SketchEllipticArc_1")]
Group_2 = model.addGroup(Part_1_doc, "Faces", Group_2_objects)
Group_2.setName("Group_ext")
Group_2.result().setName("Group_ext")
Group_2.result().setColor(0, 170, 0)
Group_3 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Revolution_1_1/From_Face")])
Group_3.setName("Face_lat1")
Group_3.result().setName("Face_lat1")
Group_4 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Revolution_1_1/To_Face")])
Group_4.setName("Face_lat2")
Group_4.result().setName("Face_lat2")
model.do()
# change revolution to be 360 degrees => no lateral faces anymore
anAngle.setValue(360)
model.end()

# check that group 3 and group 4 become invalid
assert(Group_3.groupList().value(0).isInvalid())
assert(Group_4.groupList().value(0).isInvalid())
